package com.yange.accountbook.utils


import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.util.Log
import android.widget.Toast
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.BasePopupView
import com.yange.accountbook.MyApplication
import com.yange.accountbook.R
import com.yange.accountbook.popup.LoadingPopup


/**
 * 定义的图标列表
 */
var iconList = mutableListOf(
    R.mipmap.category_e_catering_stroke,
    R.mipmap.category_e_child_stroke,
    R.mipmap.category_e_dress_stroke,
    R.mipmap.category_e_elder_stroke,
    R.mipmap.category_e_house_stroke,
    R.mipmap.category_e_medical_stroke,
    R.mipmap.category_e_money_stroke,
    R.mipmap.category_e_commodity_stroke,
    R.mipmap.category_e_communicate_stroke
)

//显示加载动画
fun showLoadingPopup(context: Context, cancel: Boolean, callBack: () -> Unit): BasePopupView {
    return XPopup.Builder(context)
        .hasStatusBarShadow(false)
        .hasShadowBg(false)
        .dismissOnBackPressed(cancel)
        .dismissOnTouchOutside(cancel)
        .asCustom(LoadingPopup(context) {
            callBack()
        })
        .show()
}


fun showToast(string: String) {
    Toast.makeText(MyApplication.mContext, string, Toast.LENGTH_SHORT).show()
}

/**
 * 复制内容到剪切板
 *
 * @param copyStr
 * @return Context.CLIPBOARD_SERVICE
 */
fun  copyStr(context: Context,copyStr:String):Boolean {
    return try {
        val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
        //clipData中的this就是需要复制的文本
        val clipData = ClipData.newPlainText("Label", copyStr)
        cm.setPrimaryClip(clipData)
        showToast("已复制到剪切板")
        true
    } catch (e:Exception ) {
        Log.i("-----","*********"+e.message)
        false
    }
}

